import { defineStore } from 'pinia'
// @ts-ignore
import { ref, reactive, computed } from "vue"
// @ts-ignore
import store from 'store'
// import config from '@/config.ts'
export const useSystem = defineStore('system', () => {
    //用户信息
    let user = computed( () =>{
        return store.get('user')
    })
    //路由信息
    let routerInfo= computed( () =>{
        return store.get('routerInfo')
    })
    //左侧路由导航条应用
    let tabs:any = reactive([])
    let tabsIndex:any = reactive([])
    let menuShow:any = ref(false)
    function saveTabs (to:any) {
        const pathNumber = to.fullPath.split('/')
        if(pathNumber.length > 3 && tabsIndex.indexOf(to.fullPath) === -1){
            tabsIndex.push(to.fullPath)
            tabs.push(to)
            store.set('tabs',tabs)
            store.set('tabsIndex',tabsIndex)
        }
    }
    function removeTabs (path:string) {
        const index = tabsIndex.indexOf(path)
        if(index > -1){
            tabsIndex.splice(index,1)
            tabs.splice(index,1)
        }
    }
    //收起展开菜单
    function menuShowSwitch () {
        menuShow.value =!menuShow.value
    }

    //首页监听路由变化
    const indexWatch = ref(0)
    function saveIndexWatch (timer:any) {
        store.set('indexWatch',timer)
        indexWatch.value = timer
    }
    return {
        user,
        routerInfo,
        indexWatch,
        saveIndexWatch,
        tabs,
        tabsIndex,
        saveTabs,
        removeTabs,
        menuShow,
        menuShowSwitch
    }
})